package ar.com.gestion.dao;

import java.util.List;

import org.springframework.jdbc.core.JdbcTemplate;

import ar.com.gestion.dominio.Pago;
import ar.com.gestion.rowmapper.PagosRowMapper;

public class PagosDAO {

	private JdbcTemplate jdbcTemplate;

	
	
	
	
	
	public int savePago(Pago pago,int id_venta){
		
		String sql = "insert into pagos (id_venta,fecha,monto) values (?,?,?)";
		 jdbcTemplate.update(sql, new Object[]{id_venta,pago.getFecha(),pago.getMonto()});
		return jdbcTemplate.queryForInt( "SELECT MAX(id) AS id FROM pagos" );
	}

	public List<Pago> getPagosByVentaID(int id_venta){
		
		String sql ="select * from pagos where id_venta = ?";
		List<Pago> pagos = jdbcTemplate.query(sql, new Object[]{id_venta},new PagosRowMapper());
		
		return pagos;
	}



	public JdbcTemplate getJdbcTemplate() {
		return jdbcTemplate;
	}


	public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
		this.jdbcTemplate = jdbcTemplate;
	}

	
	

}
